<template>
    <div>
        <div class="search-content">
            <el-form ref="searchForm" :inline="true" :model="searchContent">
                <el-form-item label="兑换日期：" prop="order_time">
                    <el-date-picker
                        v-model="searchContent.order_time"
                        type="daterange"
						value-format="yyyy-MM-dd"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                    ></el-date-picker>
                </el-form-item>
                <el-form-item label="店铺名称：" prop="store_name">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.store_name"
                        placeholder="店铺名称"
                    ></el-input>
                </el-form-item>
                <el-form-item label="申请合作商：" prop="suppliers_name" >
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.suppliers_name"
                        placeholder="申请合作商"
                    ></el-input>
                </el-form-item>
                <el-form-item prop="status" label="状态：">
                    <el-select clearable v-model="searchContent.status" placeholder="全部">
                        <el-option value="Passed" label="通过"></el-option>
                        <el-option value="Waiting" label="申请中"></el-option>
                        <el-option value="Reject" label="拒绝"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button type="primary" @click="resetSearchData">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="search-list">
            <el-table :data="goodsList" border :height="oHeight" :fit="true">
                <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                <el-table-column align="center" prop="ID" label="ID" min-width="60"></el-table-column>
                <el-table-column align="center" prop="Store" label="店铺名称" min-width="160"></el-table-column>
                <el-table-column align="center" prop="ServiceSuppliers" label="申请合作商" min-width="160"></el-table-column>
                <el-table-column align="center" prop="ApplyTime" label="申请时间" min-width="160" #default="{row}">
					{{row.ApplyTime*1000|dateFormatter('YYYY-MM-DD hh:mm:ss')}}
				</el-table-column>
				<el-table-column align="center" prop="Contacts" label="联系人" min-width="140"></el-table-column>
				<el-table-column align="center" prop="PhoneNumber" label="联系电话" min-width="130"></el-table-column>
				<el-table-column align="center" label="状态" min-width="60" #default="{row}">
					{{row.Status==='Passed'?'通过':''}}
					{{row.Status==='Waiting'?'申请中':''}}
					{{row.Status==='Reject'?'拒绝':''}}
				</el-table-column>
                <el-table-column
					fixed="right"
                    align="center"
                    prop="isInitiative"
                    label="操作"
                    min-width="160"
                    #default="{row}"
                >
					<div style="color: #5790bb">
						<span v-show="row.Status==='Waiting'||row.Status==='Reject'" @click="changeStatus(row,'Passed')">通过</span>
						<el-divider v-if="row.Status==='Waiting'" direction="vertical"></el-divider>
                        <span v-show="row.Status==='Waiting'||row.Status==='Passed'" @click="changeStatus(row,'Reject')">拒绝</span>
                    </div>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <!-- <el-button type="primary" class="btn-bottom" @click="expertData">导出检索数据</el-button> -->
                </div>
                <!--分页部分-->
                <div class="paginationOne">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.currentPage"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total*1"
                    ></el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import { dateFormatter, objScreen } from "@/common/js/util";
export default {
    data() {
        return {
            goodsList: [],
            oHeight: 800,
            searchContent: {
                currentPage: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
				store_name:'',
				status:'',
            },
            searchObj: {},
            total: 0,
        };
    },
    created() {
        this.getListData();
    },
    methods: {
		changeStatus(row,status){
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=alterMerchantApplyStatus",{
				id:row.ID,
				status
			}).then(res=>{
				if(res.code===1){
					row.Status = status;
				}else{
					this.$message.error(res.msg);
				}
			}).catch(err=>{
				this.$message.error(err);
			})
		},
        getListData() {
            var data = this.searchObj;
            data.currentPage = this.searchContent.currentPage;
            data.eachNum = this.searchContent.pageSize;
            this.$http.post('/admin/dataService/index.php?act=merchantSet&op=merchantApplyList', data).then((res) => {
                if (res.code === 1) {
                    this.total = res.data.total;
                    this.goodsList = res.data.list;
                    // this._message('success', res.msg);
                    // this.getListData();
                } else {
                    this.total = 0;
                    this.goodsList = [];
                    this._message('error', res.msg);
                }
            }).catch(err => {
                this._message('error', err);
            })
        },
        search() {
            this.searchContent.currentPage = 1;
			let {store_name,suppliers_name,status,order_time} = this.searchContent;
            this.searchObj = objScreen({
                start_time_from: order_time[0],
				start_time_to: order_time[1],
				store_name,
				suppliers_name,
				status
            })
            this.getListData();
        },
        resetSearchData() {
            this.$refs['searchForm'].resetFields();
        },
        handleSizeChange(pageSize) {
            localStorage.setItem('pageSize', pageSize);
            this.searchContent.pageSize = pageSize;
            this.searchContent.currentPage = 1;
            this.getListData();
        },
        handleCurrentChange(page) {
            this.searchContent.currentPage = page;
            this.getListData();
        },
    },
    mounted() {
        resize(this)
    },
};
</script>
<style lang="scss" scoped>
.bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-content-input {
    width: 200px;
}
</style>